.TH std::basic_streambuf 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_streambuf \- std::basic_streambuf

.SH Synopsis
   Defined in header <streambuf>
   template<

       class CharT,
       class Traits = std::char_traits<CharT>

   > class basic_streambuf;

   The class basic_streambuf controls input and output to a character sequence. It
   includes and provides access to

    1. The controlled character sequence, also called the buffer, which may contain
       input sequence (also called get area) for buffering the input operations and/or
       output sequence (also called put area) for buffering the output operations.
    2. The associated character sequence, also called source (for input) or sink (for
       output). This may be an entity that is accessed through OS API (file, TCP
       socket, serial port, other character device), or it may be an object
       (std::vector, array, string literal), that can be interpreted as a character
       source or sink.

   The I/O stream objects std::basic_istream and std::basic_ostream, as well as all
   objects derived from them (std::ofstream, std::stringstream, etc), are implemented
   entirely in terms of std::basic_streambuf.

   The controlled character sequence is an array of CharT which, at all times,
   represents a subsequence, or a "window" into the associated character sequence. Its
   state is described by three pointers:

    1. The beginning pointer, always points at the lowest element of the buffer.
    2. The next pointer, points at the element that is the next candidate for reading
       or writing.
    3. The end pointer, points one past the end of the buffer.

   A basic_streambuf object may support input (in which case the buffer described by
   the beginning, next, and end pointers is called get area), output (put area), or
   input and output simultaneously. In latter case, six pointers are tracked, which may
   all point to elements of the same character array or two individual arrays.

   If the next pointer is less than the end pointer in the put area, a write position
   is available. The next pointer can be dereferenced and assigned to.

   If the next pointer is less than the end pointer in the get area, a read position is
   available. The next pointer can be dereferenced and read from.

   If the next pointer is greater than the beginning pointer in a get area, a putback
   position is available, and the next pointer may be decremented, dereferenced, and
   assigned to, in order to put a character back into the get area.

   The character representation and encoding in the controlled sequence may be
   different from the character representations in the associated sequence, in which
   case a std::codecvt locale facet is typically used to perform the conversion. Common
   examples are UTF-8 (or other multibyte) files accessed through std::wfstream
   objects: the controlled sequence consists of wchar_t characters, but the associated
   sequence consists of bytes.

   Typical implementation of the std::basic_streambuf base class holds only the six
   CharT* pointers and a copy of std::locale as data members. In addition,
   implementations may keep cached copies of locale facets, which are invalidated
   whenever imbue() is called. The concrete buffers such as std::basic_filebuf or
   std::basic_stringbuf are derived from std::basic_streambuf.

   std-streambuf.svg

   Several typedefs for common character types are provided:

   Defined in header <streambuf>
   Type            Definition
   std::streambuf  std::basic_streambuf<char>
   std::wstreambuf std::basic_streambuf<wchar_t>

.SH Member types

   Member type Definition
   char_type   CharT
   traits_type Traits; the program is ill-formed if Traits::char_type is not
               CharT.
   int_type    Traits::int_type
   pos_type    Traits::pos_type
   off_type    Traits::off_type

.SH Member functions

   destructor         destructs the basic_streambuf object
   \fB[virtual]\fP          \fI(virtual public member function)\fP
.SH Locales
   pubimbue           invokes imbue()
                      \fI(public member function)\fP
   getloc             obtains a copy of the associated locale
                      \fI(public member function)\fP
.SH Positioning
   pubsetbuf          invokes setbuf()
                      \fI(public member function)\fP
   pubseekoff         invokes seekoff()
                      \fI(public member function)\fP
   pubseekpos         invokes seekpos()
                      \fI(public member function)\fP
   pubsync            invokes sync()
                      \fI(public member function)\fP
.SH Get area
                      obtains the number of characters immediately available in the get
   in_avail           area
                      \fI(public member function)\fP
                      advances the input sequence, then reads one character without
   snextc             advancing again
                      \fI(public member function)\fP
   sbumpc             reads one character from the input sequence and advances the
   stossc             sequence
   (removed in C++17) \fI(public member function)\fP
                      reads one character from the input sequence without advancing the
   sgetc              sequence
                      \fI(public member function)\fP
   sgetn              invokes xsgetn()
                      \fI(public member function)\fP
.SH Put area
                      writes one character to the put area and advances the next
   sputc              pointer
                      \fI(public member function)\fP
   sputn              invokes xsputn()
                      \fI(public member function)\fP
.SH Putback
   sputbackc          puts one character back in the input sequence
                      \fI(public member function)\fP
   sungetc            moves the next pointer in the input sequence back by one
                      \fI(public member function)\fP
.SH Protected member functions
   constructor        constructs a basic_streambuf object
                      \fI(protected member function)\fP
   operator=          replaces a basic_streambuf object
   \fI(C++11)\fP            \fI(protected member function)\fP
   swap               swaps two basic_streambuf objects
   \fI(C++11)\fP            \fI(protected member function)\fP
.SH Locales
   imbue              changes the associated locale
   \fB[virtual]\fP          \fI(virtual protected member function)\fP
.SH Positioning
   setbuf             replaces the buffer with user-defined array, if permitted
   \fB[virtual]\fP          \fI(virtual protected member function)\fP
   seekoff            repositions the next pointer in the input sequence, output
   \fB[virtual]\fP          sequence, or both, using relative addressing
                      \fI(virtual protected member function)\fP
   seekpos            repositions the next pointer in the input sequence, output
   \fB[virtual]\fP          sequence, or both using absolute addressing
                      \fI(virtual protected member function)\fP
   sync               synchronizes the buffers with the associated character sequence
   \fB[virtual]\fP          \fI(virtual protected member function)\fP
.SH Get area
   showmanyc          obtains the number of characters available for input in the
   \fB[virtual]\fP          associated input sequence, if known
                      \fI(virtual protected member function)\fP
   underflow          reads characters from the associated input sequence to the get
   \fB[virtual]\fP          area
                      \fI(virtual protected member function)\fP
   uflow              reads characters from the associated input sequence to the get
   \fB[virtual]\fP          area and advances the next pointer
                      \fI(virtual protected member function)\fP
   xsgetn             reads multiple characters from the input sequence
   \fB[virtual]\fP          \fI(virtual protected member function)\fP
   eback              returns a pointer to the beginning, current character and the end
   gptr               of the get area
   egptr              \fI(protected member function)\fP
   gbump              advances the next pointer in the input sequence
                      \fI(protected member function)\fP
                      repositions the beginning, next, and end pointers of the input
   setg               sequence
                      \fI(protected member function)\fP
.SH Put area
   xsputn             writes multiple characters to the output sequence
   \fB[virtual]\fP          \fI(virtual protected member function)\fP
   overflow           writes characters to the associated output sequence from the put
   \fB[virtual]\fP          area
                      \fI(virtual protected member function)\fP
   pbase              returns a pointer to the beginning, current character and the end
   pptr               of the put area
   epptr              \fI(protected member function)\fP
   pbump              advances the next pointer of the output sequence
                      \fI(protected member function)\fP
                      repositions the beginning, next, and end pointers of the output
   setp               sequence
                      \fI(protected member function)\fP
.SH Putback
   pbackfail          puts a character back into the input sequence, possibly modifying
   \fB[virtual]\fP          the input sequence
                      \fI(virtual protected member function)\fP

.SH See also

        object type, capable of holding all information needed to control a C I/O
   FILE stream
        \fI(typedef)\fP
